package com.example.crmdemo.Crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.crmdemo.Crm.entity.Area;
import com.example.crmdemo.Crm.entity.Customer;
import com.example.crmdemo.Crm.entity.Operation;
import com.example.crmdemo.Crm.service.AreaService;
import com.example.crmdemo.Crm.service.CustomerService;
import com.example.crmdemo.Crm.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/operation")
public class OperationController {

    @Autowired
    private OperationService operationService;

    @Autowired
    private CustomerService customerService;

    @Autowired
    private AreaService areaService;

    // 添加业务
    @PostMapping("/add")
    public boolean addOperation(@RequestBody Operation operation) {
        return operationService.save(operation);
    }

    // 删除业务
    @DeleteMapping("/delete/{id}")
    public boolean deleteOperation(@PathVariable Long id) {
        return operationService.removeById(id);
    }

    // 修改业务信息
    @PutMapping("/update")
    public boolean updateOperation(@RequestBody Operation operation) {
        return operationService.updateById(operation);
    }

    // 按业务名查询业务
    @GetMapping("/get/{name}")
    public List<Operation> getOperationByName(@PathVariable String name) {
        QueryWrapper<Operation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("o_name", name);
        return operationService.list(queryWrapper);
    }

    // 获取所有业务信息
    @GetMapping("/getall")
    public List<Operation> getAllOperations() {
        return operationService.list();
    }

    // 获取所有客户信息
    @GetMapping("/customers")
    public List<Customer> getAllCustomers() {
        return customerService.list();
    }

    // 获取所有区域信息
    @GetMapping("/areas")
    public List<Area> getAllAreas() {
        return areaService.list();
    }
}
